package com.lits.file.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.lits.file.common.UploadUtil;

/**
 * Created by lzm on 2018/4/20.
 */
@Configuration
@ConfigurationProperties(prefix = "file.upload.cfg")
public class LocalFileUploadCfg {
	/** 所有上传文件的根目录 */
	private String baseDir;

	/** 下载应用文件的目录 */
	private String appDownloadBaseDir;

	/** 上传应用的根目录 */
	private String appBaseDir;

	/** 上传应用的读写缓存 */
	private int readBuffer;

	/**
	 * 文件最大大小
	 */
	private int maxUploadM;

	public String getBaseDir() {
		return baseDir;
	}

	public void setDirBaseDir(String dirBaseDir) {
		if (UploadUtil.checkDirEnd(dirBaseDir)) {
			throw new IllegalArgumentException("上传文件路径必须以'/'结尾");
		}
		this.baseDir = dirBaseDir;
	}

	public String getAppDownloadBaseDir() {
		return appDownloadBaseDir;
	}

	public void setAppDownloadBaseDir(String appDownloadBaseDir) {
		if (UploadUtil.checkDirEnd(appDownloadBaseDir)) {
			throw new IllegalArgumentException("上传文件路径必须以'/'结尾");
		}
		this.appDownloadBaseDir = appDownloadBaseDir;
	}

	public String getAppBaseDir() {
		return appBaseDir;
	}

	public void setAppBaseDir(String appBaseDir) {
		if (UploadUtil.checkDirEnd(appBaseDir)) {
			throw new IllegalArgumentException("上传文件路径必须以'/'结尾");
		}
		this.appBaseDir = appBaseDir;
	}

	public int getReadBuffer() {
		return readBuffer;
	}

	public void setReadBuffer(int readBuffer) {
		if (readBuffer <= 0) {
			this.readBuffer = 3 * 1024 * 1024;
		} else {
			this.readBuffer = readBuffer;
		}
	}

	public int getMaxUploadM() {
		return maxUploadM;
	}

	public void setMaxUploadM(int maxUploadM) {
		this.maxUploadM = maxUploadM;
	}

}
